/*
 * ============================================================================
 * Copyright Notice!
 * ----------------------------------------------------------------------------
 * This file contains proprietary and confidential information belonging to the
 * group of people involvled in developing this project.  Reproduction, disclosure 
 * or use without specific written authorization from project stake holders is 
 * prohibited. Please refer the readme.txt in project installation folder for more
 * specific contacts
 *
 * All rights reserved.
 * ============================================================================
 */
package edu.uwm.universitydb.dao.student;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import edu.uwm.universitydb.model.Student;

/**
 * <code>SearchStudentsByProjectId</type>
 * 
 * @author Shyam Nair
 */
public class SearchStudentsByProjectId extends SearchStudentCommandBase<List<Student>>
{
    /** sql portion representing where clause for name */
    private static final String SQL_PART2 =
        " , university.supervises where "
            + "university.supervises.pno = ? AND university.supervises.grad_ssn = s.grad_ssn";

    /** attribute holding the name */
    private final String mProjectNum;

    /**
     * 
     * @param projectNum
     */
    public SearchStudentsByProjectId(final String projectNum)
    {
        mProjectNum = projectNum;
    }

    /*
     * (non-javadoc)
     * @see edu.uwm.universitydb.framework.db.command.DataFetchCommand#processResult(java.sql.ResultSet)
     */
    @Override
    public List<Student> processResult(final ResultSet result) throws SQLException
    {
        final List<Student> studentList = new ArrayList<Student>();
        while (result.next())
        {
            final Student professor = getStudent(result);
            studentList.add(professor);
        }
        return studentList;
    }

    /*
     * (non-javadoc)
     * @see edu.uwm.universitydb.framework.db.command.DBCommand#getSQL()
     */
    @Override
    public String getSQL()
    {
        return SELECT_SQL + SQL_PART2;
    }

    /*
     * (non-javadoc)
     * @see edu.uwm.universitydb.framework.db.command.DBCommand#setParameters(java.sql.PreparedStatement)
     */
    @Override
    public void setParameters(final PreparedStatement pStmt) throws SQLException
    {
        pStmt.setString(1, mProjectNum);
    }
}

/*
 * ============================================================================
 * Change History
 * ----------------------------------------------------------------------------
 * Apr 30, 2014   Shyam Nair
 * File created
 * ----------------------------------------------------------------------------
 */